<template>
  <view class="p-h24 p-t40" style="padding-bottom: 208rpx">
    <ResumePreview v-if="resume" :resume="resume" />
    <view class="p-h24 flex-sb bg-1 foot">
      <view class="flex-1 flex">
        <view class="flex-d-c action" @click="handleCollect">
          <image class="icon" src="@/static/images/public/collect.png" mode="aspectFit" />
          <text class="text-400-128">收藏</text>
        </view>
        <view class="flex-d-c action" @click="handleRejectResume">
          <image class="icon" src="@/static/images/public/collect.png" mode="aspectFit" />
          <text class="text-400-128">不合适</text>
        </view>
      </view>
      <RcButton
        :width="192"
        text="通知面试"
        :top="0"
        :size="28"
        @click="interviewNoticeVisible = true" />
    </view>
    <up-popup
      :show="interviewNoticeVisible"
      mode="bottom"
      closeOnClickOverlay
      @close="interviewNoticeVisible = false">
      <InterviewNotice @close="interviewNoticeVisible = false" />
    </up-popup>
  </view>
</template>

<script lang="ts" setup>
  import { ref } from 'vue'
  import { onLoad } from '@dcloudio/uni-app'
  import RcButton from '@/components/button.vue'
  import InterviewNotice from './components/interview-notice'
  import type { TResume } from '@/types/api.d'
  import ResumePreview from '@/components/resume-preview'

  const resume = ref<TResume | null>(null)
  const interviewNoticeVisible = ref(false)

  const handleCollect = () => {
    uni.showLoading({ mask: true })

    // /resume/addsc
    // /resume/delsc
    uni.$u.post('/resume/addsc', { user_id: resume.value!.id }).then((res) => {
      uni.$u.toast(res.msg)
      if (res.code === 1) {
        // 更新简历信息
      }
    }).finally(() => {
      uni.hideLoading()
    })
  }

  const handleRejectResume = () => {
    uni.showLoading({ mask: true })

    uni.$u.post('/resume/nojl', { company_id: '', user_id: resume.value!.id }).then((res) => {
      uni.$u.toast(res.msg)
      if (res.code === 1) {
        // 更新简历信息
      }
    }).finally(() => {
      uni.hideLoading()
    })
  }

  const getInfo = () => {
    try {
      uni.getStorage({
        key: 'new_resume_info',
        success: (res) => {
          resume.value = JSON.parse(res.data)
          console.log(resume.value)
        },
      })
    } catch (e) {}
  }

  onLoad(() => {
    getInfo()
  })
</script>

<style lang="scss">
	page {
		background-color: $page-color-4;
	}
</style>

<style lang="scss" scoped>
	.foot {
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		height: 168rpx;
		.action {
			width: 100rpx;
		}
		.icon {
			width: 48rpx;
			height: 48rpx;
		}
	}
</style>
